//
//  WPReadingInvidialRanking.m
//  wobingwoyi
//
//  Created by WGP on 16/8/23.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPReadingInvidialRanking.h"
#import "WPReadingViewCollectionViewCell.h"
#import "WPMineLoginVC.h"
#import "WPReadingRankingCommentVC.h"
#import "WPDiagnosisViewController.h"
#import "WPTreatmentInstructionsVC.h"
#import "WPNewDiseaseInstructionView.h"
#import "SwipeBack.h"
#import "WPExceptionalVC.h"
#import "WPReadingSharedBtn.h"
#import "WPReadingSharedBtnModel.h"

#define kPopViewHeight (290*SCALE_FULL)
#define kMargin  16
#define kBaseTag 100000
#define kSecondBaseTag 100100

@interface WPReadingInvidialRanking ()<UICollectionViewDelegate,UICollectionViewDataSource,MWPhotoBrowserDelegate>

@property(nonatomic,strong)UIViewController *firstVC;
@property(nonatomic,strong)UIViewController *secondVC;
@property(nonatomic,strong)UIViewController *thirdVC;

@property(nonatomic,strong)NSArray *photos;
@property(nonatomic,strong)UIView *sharedPopView;
@property(nonatomic,strong)UIButton *coverBtn;

@property(nonatomic,strong)NSArray *firstArr;
@property(nonatomic,strong)NSArray *secondArr;
@property(nonatomic,strong)NSArray *sharedTypeArr;

@end

@implementation WPReadingInvidialRanking

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = GlobalBgColor;
    self.titleLabel.text = self.model.name;
    
    self.lineView.hidden = YES;
    [self.collectionView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleView.mas_bottom);
    }];
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    [self.collectionView registerClass:[WPReadingViewCollectionViewCell class] forCellWithReuseIdentifier:@"first"];
    [self.collectionView registerClass:[WPReadingViewCollectionViewCell class] forCellWithReuseIdentifier:@"second"];
    [self.collectionView registerClass:[WPReadingViewCollectionViewCell class] forCellWithReuseIdentifier:@"third"];
    
    [self readingSetupUI];
    
    UIButton *exceptionalBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [exceptionalBtn setBackgroundImage:[UIImage imageNamed:@"exceptional_icon"] forState:UIControlStateNormal];
    [exceptionalBtn setBackgroundImage:[UIImage imageNamed:@"exceptionalIcon_selected"] forState:UIControlStateHighlighted];
    [self.view addSubview:exceptionalBtn];
    [exceptionalBtn addTarget:self action:@selector(exceptionalBtnDidClick) forControlEvents:UIControlEventTouchUpInside];
    [exceptionalBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-58);
    }];
    
    //如果示例病例的话就隐藏答谢按钮
    if(self.isExample || self.isChargeExample)
    {
        exceptionalBtn.hidden = YES;
    }
}

-(void)titleLabelDidClick
{
//    self.hidesBottomBarWhenPushed = YES;
    WPNewDiseaseInstructionView *rirVC = [WPNewDiseaseInstructionView new];
    rirVC.disease = self.model.name;
    rirVC.isWhite = YES;
    [self presentViewController:rirVC animated:YES completion:nil];

}

-(void)readingSetupUI
{
    UIButton *threePointBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [threePointBtn setImage:[UIImage imageNamed:@"threePoint_normal"] forState:UIControlStateNormal];
    [threePointBtn setBackgroundImage:[UIImage imageNamed:@"threePoint_highlight"] forState:UIControlStateSelected];
    [threePointBtn addTarget:self action:@selector(threePointBtnDidClick:) forControlEvents:UIControlEventTouchDown];
    [self.navBarView addSubview:threePointBtn];
    
    [threePointBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.top.bottom.equalTo(self.navBarView);
        make.right.equalTo(self.navBarView).offset(-6);
        make.width.mas_equalTo(44);
    }];
    
    //收藏
//    UIButton *collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    self.collectionBtn = collectBtn;
//    
//    [collectBtn setBackgroundImage:[UIImage imageNamed:@"reading_collection_normal"] forState:UIControlStateNormal];
//    [collectBtn setBackgroundImage:[UIImage imageNamed:@"reading_collection_highlight"] forState:UIControlStateSelected];
//    [collectBtn addTarget:self action:@selector(collectBtnDidClick:) forControlEvents:UIControlEventTouchDown];
//    [self.navBarView addSubview:collectBtn];
//    
//    [collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.navBarView);
//        make.right.equalTo(self.navBarView).offset(-10);
//    }];
    
    //点赞
//    UIButton *sharedBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [sharedBtn setBackgroundImage:[UIImage imageNamed:@"caseLikeBtn_normal"] forState:UIControlStateNormal];
//    [sharedBtn setBackgroundImage:[UIImage imageNamed:@"caseLikeBtn_selected"] forState:UIControlStateSelected];
//    [sharedBtn addTarget:self action:@selector(sharedBtnDidClick:) forControlEvents:UIControlEventTouchDown];
//    [self.navBarView addSubview:sharedBtn];
//
//    [sharedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.navBarView);
//        make.right.equalTo(self.collectionBtn.mas_left).offset(-10);
//    }];
}

#pragma mark - 按钮点击事件

-(void)threePointBtnDidClick:(UIButton *)btn
{
    if (!self.coverBtn)
    {
        UIButton *coverBtn  = [UIButton buttonWithType:UIButtonTypeCustom];
        self.coverBtn = coverBtn;
        coverBtn.frame = self.view.bounds;
        coverBtn.backgroundColor = RGBA_COLOR(51, 51, 51, 0.5);
        [coverBtn addTarget:self action:@selector(coverBtnDidClick:) forControlEvents:UIControlEventTouchDown];
        [self.view addSubview:coverBtn];
    }
    
    if(!self.sharedPopView)
    {
        self.sharedPopView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, kPopViewHeight)];
        [self setupSharedPopView];
        self.sharedPopView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:self.sharedPopView];
    }
    
    [UIView animateWithDuration:0.3 animations:^{
        
        self.sharedPopView.frame = CGRectMake(0, SCREEN_HEIGHT-kPopViewHeight, SCREEN_WIDTH, kPopViewHeight);
        self.coverBtn.alpha = 0.5;
    }];
}

-(void)sharedBtnDidClick:(UIButton *)btn
{
    if (![WPUserAccountViewModel sharedInstance].userLogin)
    {
        [[WPUserAccountViewModel sharedInstance] loginTipWith:^{
            
            WPMineLoginVC *vc = [WPMineLoginVC new];
            [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
        }];
        return ;
    }
    
    if (btn.selected)
    {
        [self showInfoStatus:@"已赞过"];
        return ;
    }
    //点赞
    NSString *url = @"record/praise.do";
    NSDictionary *dict = @{@"recordId":@(self.model.id)};
    
    [self showWithStatus:nil];
    
    [[WPNetWorkManager sharedNetWorkManager] POST:url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [self dismiss];
        
        NSDictionary *responseDict = (NSDictionary *)responseObject;
        if ([responseDict[@"result"] isEqualToString:@"success"])
        {
            btn.selected = !btn.selected;
            [self showSuccessInfoWithStatus:@"点赞成功"];
        }
        else
        {
            if ([responseDict[@"detail"] isEqualToString:@"alreadyPraise"])
            {
                [self showInfoStatus:@"已赞过"];
                
            }//考虑到账号过期的情况
            else if ([responseObject[@"detail"] isEqualToString:@"illegalLogin"])
            {
                //账号过期
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"账号过期,请重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alertView show];
            }
            else
            {
                [self showErrorInfoWithStatus:@"网络错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        WPLog(@"%@",error);
        [self showErrorInfoWithStatus:@"网络错误"];
    }];
    
}

-(void)collectBtnDidClick:(UIButton *)btn
{
    if (![WPUserAccountViewModel sharedInstance].userLogin)
    {
        [[WPUserAccountViewModel sharedInstance] loginTipWith:^{
            
            WPMineLoginVC *vc = [WPMineLoginVC new];
            [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
        }];
        return ;
    }
    
    if (btn.selected)
    {
        [self showInfoStatus:@"已收藏过"];
        return ;
    }
    
    NSString *url = @"record/collectRecord.do";
    NSDictionary *dict = @{@"recordId":@(self.model.id)};
    
    [self showWithStatus:nil];
    
    [[WPNetWorkManager sharedNetWorkManager] POST:url parameters:dict progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        [self dismiss];
        
        NSDictionary *responseDict = (NSDictionary *)responseObject;
        if ([responseDict[@"result"] isEqualToString:@"success"])
        {
            btn.selected = !btn.selected;
            [self showSuccessInfoWithStatus:@"收藏成功"];
        }
        else
        {
            if ([responseDict[@"detail"] isEqualToString:@"重复收藏"])
            {
                [self showInfoStatus:@"已收藏过"];
                
            }//            考虑到账号过期的情况
            else if ([responseObject[@"detail"] isEqualToString:@"illegalLogin"])
            {
                //                账号过期
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"账号过期,请重新登录" delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
                [alertView show];
            }
            else
            {
                [self showErrorInfoWithStatus:@"网络错误"];
            }
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
        [self showErrorInfoWithStatus:@"网络错误"];
        
    }];
}

-(void)coverBtnDidClick:(UIButton *)coverBtn
{
    [UIView animateWithDuration:0.3 animations:^{
        
        self.sharedPopView.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, kPopViewHeight);
        coverBtn.alpha = 0.0;
    }];
}

-(void)cancelBtnDidClick
{
    [self coverBtnDidClick:self.coverBtn];
}

-(void)shareBtnDidClick:(WPReadingSharedBtn *)btn
{
    
    BOOL isSharedBtn = NO;
    NSUInteger typeUI = 0;
    
    if (btn.tag == kBaseTag)
    {
        typeUI = [self.sharedTypeArr[0] unsignedIntegerValue];
        isSharedBtn = YES;
    }
    else if(btn.tag == (kBaseTag + 1))
    {
        typeUI = [self.sharedTypeArr[1] unsignedIntegerValue];
        isSharedBtn = YES;
    }
    else if(btn.tag == (kBaseTag + 2))
    {
        typeUI = [self.sharedTypeArr[2] unsignedIntegerValue];
        isSharedBtn = YES;
    }
    else if(btn.tag == (kBaseTag + 3))
    {
        typeUI = [self.sharedTypeArr[3] unsignedIntegerValue];
        isSharedBtn = YES;
    }
    
    if (isSharedBtn)
    {
        [self showWithStatus:nil];
        
        NSString *url = @"record/spreadRecord.do";
        [[WPNetWorkManager sharedNetWorkManager] POST:url parameters:@{@"recordId":@(self.model.id)} progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            [self dismiss];
            if([responseObject[@"result"] isEqualToString:@"success"])
            {
                NSDictionary *result = responseObject[@"detail"];
                
                NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
                [shareParams SSDKSetupShareParamsByText:result[@"content"]
                                                 images:[UIImage imageNamed:@"80"] //传入要分享的图片
                                                    url:result[@"url"]
                                                  title:result[@"name"]
                                                   type:SSDKContentTypeAuto];
                
                [ShareSDK share:typeUI
                     parameters:shareParams
                 onStateChanged:^(SSDKResponseState state, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error) {
                     
                     
                     if (error)
                     {
                         WPLog(@"%@",error);
                         
                         if (error.code == 208)
                         {
                             NSString *platform = nil;
                             if (btn.tag == 0 || btn.tag == 1 || btn.tag == 4)
                             {
                                 platform = @"微信";
                             }
                             else if(btn.tag == 2 || btn.tag == 3)
                             {
                                 platform = @"QQ";
                             }
                             
                             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:[NSString stringWithFormat:@"您的设备没有安装%@",platform] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil];
                             [alertView show];
                         }
                     }
                     else
                     {
                         WPLog(@"%@",userData);
                     }
                     
                 }];

            }
            else
            {
                //            考虑到账号过期的情况
                if ([responseObject[@"detail"] isEqualToString:@"illegalLogin"])
                {
                    //账号过期
                    [self illegalLoginWithSuccessBlock:^{
                        
                        WPMineLoginVC *vc = [WPMineLoginVC new];
                        [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
                    }];
                }
                else
                {
                    [self showErrorInfoWithStatus:@"服务器错误"];
                }
            }
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            [self showErrorInfoWithStatus:@"网络错误"];
        }];
        
    }
    else
    {
        if(btn.tag == kSecondBaseTag)
        {
            [self sharedBtnDidClick:nil];
        }
        else if(btn.tag == (kSecondBaseTag + 1))
        {
            [self collectBtnDidClick:nil];
        }
    }
    
    [self coverBtnDidClick:self.coverBtn];
}

-(void)setupSharedPopView
{
    UIScrollView *firstScrollView = [[UIScrollView alloc] init];
    firstScrollView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 120*SCALE_FULL);
    firstScrollView.backgroundColor = RGB_SAME(245);
    firstScrollView.showsHorizontalScrollIndicator = NO;
    firstScrollView.bounces = NO;
    [self.sharedPopView addSubview:firstScrollView];
    
    CGFloat width = (SCREEN_WIDTH-3*kMargin)/4.0;
    
    for (int i = 0; i < self.firstArr.count; i++)
    {
        WPReadingSharedBtnModel *model = self.firstArr[i];
        
        WPReadingSharedBtn *btn = [WPReadingSharedBtn buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",model.imageName]] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlight",model.imageName]] forState:UIControlStateHighlighted];
        [btn setTitle:model.title forState:UIControlStateNormal];
        [btn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(shareBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.backgroundColor = RGB_SAME(245);
        btn.tag = i + kBaseTag;
        CGFloat x = i * (width + kMargin);
        btn.frame = CGRectMake(x, 0, width, 120*SCALE_FULL);
        [firstScrollView addSubview:btn];
    }
    
    firstScrollView.contentSize = CGSizeMake(self.firstArr.count * width + (self.firstArr.count-1)*kMargin, 0);
    
    
    UIScrollView *secondScrollview = [[UIScrollView alloc] init];
    secondScrollview.backgroundColor = RGB_SAME(245);
    secondScrollview.showsHorizontalScrollIndicator = NO;
    secondScrollview.bounces = NO;
    [self.sharedPopView addSubview:secondScrollview];
    
    [secondScrollview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(firstScrollView.mas_bottom);
        make.left.right.height.equalTo(firstScrollView);
    }];
    
    for (int i = 0; i < self.secondArr.count; i++)
    {
        WPReadingSharedBtnModel *model = self.secondArr[i];
        
        WPReadingSharedBtn *btn = [WPReadingSharedBtn buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",model.imageName]] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlight",model.imageName]] forState:UIControlStateHighlighted];
        [btn setTitle:model.title forState:UIControlStateNormal];
        [btn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(shareBtnDidClick:) forControlEvents:UIControlEventTouchUpInside];
        btn.titleLabel.font = [UIFont systemFontOfSize:13];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.backgroundColor = RGB_SAME(245);
        btn.tag = i + kSecondBaseTag;
        CGFloat x = i * (width + kMargin);
        btn.frame = CGRectMake(x, 0, width, 120*SCALE_FULL);
        [secondScrollview addSubview:btn];
    }
    
    secondScrollview.contentSize = CGSizeMake(self.secondArr.count * width + (self.secondArr.count-1)*kMargin, 0);
    
    UIImageView *lineView = [UIImageView lineImageView];
    [self.sharedPopView addSubview:lineView];
    lineView.frame = CGRectMake(0, 120*SCALE_FULL, SCREEN_WIDTH, 0.5);
    
    UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.sharedPopView addSubview:cancelBtn];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
    [cancelBtn addTarget:self action:@selector(cancelBtnDidClick) forControlEvents:UIControlEventTouchDown];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(self.sharedPopView);
        make.top.equalTo(secondScrollview.mas_bottom);
    }];
    
}

//重新登陆的代理方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        WPMineLoginVC *vc = [WPMineLoginVC new];
        [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
        
        vc.successLoginBlock = ^
        {
            self.collectionBtn.selected = !self.collectionBtn.selected;
            [self showSuccessInfoWithStatus:@"收藏成功"];
        };

    }
}

#pragma mark - collectionView的代理方法
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 3;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.item == 0)
    {
        WPReadingViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"first" forIndexPath:indexPath];
        
        if (!cell.tvc)
        {
            WPDiagnosisViewController *vc = [[WPDiagnosisViewController alloc] initWithStyle:UITableViewStyleGrouped];
            self.firstVC = vc;
            vc.isExample = self.isExample;
            
            __weak typeof(self) weakSelf = self;
            vc.diseaseInstructionBlock = ^(NSString *disease)
            {
                //跳转到百科
                [weakSelf titleLabelDidClick];
            };
            
            vc.model = self.model;
            cell.tvc = vc;
            
            [self addChildViewController:vc];
        }
        
        return cell;
    }
    else if(indexPath.item == 1)
    {
        WPReadingViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"second" forIndexPath:indexPath];
        
        WPTreatmentInstructionsVC *vc = [WPTreatmentInstructionsVC new];
        self.secondVC = vc;
        vc.isChargeExample = self.isChargeExample;
        cell.tvc = vc;
        vc.model = self.model;
        
        [self addChildViewController:vc];
        return cell;
    }
    else
    {
        WPReadingViewCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"third" forIndexPath:indexPath];
        
        if(!cell.tvc)
        {
            WPReadingRankingCommentVC *vc = [WPReadingRankingCommentVC new];
            self.thirdVC = vc;
            cell.tvc = vc;
            vc.model = self.model;
            //如果一个控制器的View作为另一个控制器的子控件那么这个控制器也应该作为另一个控制器的子控制器
            [self addChildViewController:vc];
        }
        
        return cell;
    }
}

-(void)setModel:(WPMRModel *)model
{
    _model = model;
    
}


#pragma mark - 按钮响应事件
-(void)exceptionalBtnDidClick
{
    if (![WPUserAccountViewModel sharedInstance].userLogin)
    {
        [[WPUserAccountViewModel sharedInstance] loginTipWith:^{
            
            WPMineLoginVC *vc = [WPMineLoginVC new];
            [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
        }];
        return ;
    }
    
    WPExceptionalVC *vc = [WPExceptionalVC new];
    self.hidesBottomBarWhenPushed = YES;
    vc.model = self.model;
    [self.navigationController pushViewController:vc animated:YES];
}

//点击标题滚动collectionView
-(void)titleBtnDidClick:(WPBtnNoHighLight *)btn
{
    [super titleBtnDidClick:btn];
    
    [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:btn.tag-1 inSection:0] atScrollPosition:UICollectionViewScrollPositionNone animated:YES];
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = scrollView.contentOffset.x/scrollView.bounds.size.width;
    [self titleBtnDidClick:[self.view viewWithTag:index+1]];
}


//返回图片个数
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser{
    return self.photos.count;
}

//返回图片模型
- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index{
    
    if (index < self.photos.count)
    {
        return [self.photos objectAtIndex:index];
    }
    return nil;
    
}

-(NSArray *)firstArr
{
    if (_firstArr == nil)
    {
        WPReadingSharedBtnModel *model1 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_wx" title:@"微信"];
        WPReadingSharedBtnModel *model2 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_wxTL" title:@"朋友圈"];
        WPReadingSharedBtnModel *model3 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_wb" title:@"微博"];
        WPReadingSharedBtnModel *model4 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_qq" title:@"QQ"];
        
        _firstArr = [NSArray arrayWithObjects:model1,model2,model3,model4, nil];
    }
    return _firstArr;
}

-(NSArray *)secondArr
{
    if (_secondArr == nil)
    {
        WPReadingSharedBtnModel *model1 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_zan" title:@"病例点赞"];
        WPReadingSharedBtnModel *model2 = [WPReadingSharedBtnModel readingSharedBtnModelWith:@"reading_like" title:@"病例收藏"];
        
        _secondArr = [NSArray arrayWithObjects:model1,model2, nil];
    }
    return _secondArr;
}

-(NSArray *)sharedTypeArr
{
    if (_sharedTypeArr == nil)
    {
        _sharedTypeArr = @[
                           @(SSDKPlatformTypeWechat),
                           @(SSDKPlatformSubTypeWechatTimeline),
                           @(SSDKPlatformTypeSinaWeibo),
                           @(SSDKPlatformSubTypeQQFriend),
                           ];
    }
    return _sharedTypeArr;
}

-(void)backBtnDidClick
{
    self.firstVC = nil;
    self.secondVC = nil;
    self.thirdVC = nil;
    
    if (self.isDismiss)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [super backBtnDidClick];
    }
    
    [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}

-(void)dealloc
{
    WPLog(@"WPReadingInvidialRanking控制器死了");
}
@end
